package com.example.manage.controller;

import com.example.manage.bean.ClientBannerBean;
import com.example.manage.bean.PayCostBean;
import com.example.manage.bean.ResultBean;
import com.example.manage.mapper.ClientBannerMapper;
import com.example.manage.mapper.ParkingChargeMapper;
import com.example.manage.mapper.PayCostMapper;
import com.example.manage.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/payCost")
public class PayCostController {
    @Autowired
    PayCostMapper payCostMapper;

    @Autowired
    ParkingChargeMapper parkingChargeMapper;

    @RequestMapping("/updateParkingCharge")
    @ResponseBody
    public ResultBean updateParkingCharge(@RequestBody Map<String, Float> params) {
        int count = parkingChargeMapper.updateParkingCharge(params.get("parkingCharge"));
        return ResultUtil.getResultBean(count, "修改失败");
    }

    @RequestMapping("/getParkingCharge")
    @ResponseBody
    public ResultBean getParkingCharge() {
        float parkingCharge = parkingChargeMapper.getParkingCharge();
        return ResultUtil.getSuccessBean(parkingCharge, "获取成功");
    }


    @RequestMapping("/pay")
    @ResponseBody
    public ResultBean pay(@RequestBody Map<String, Integer> params) {
        int count = payCostMapper.pay(params.get("id"));
        return ResultUtil.getResultBean(count, "支付失败");
    }

    @RequestMapping("/addCost")
    @ResponseBody
    public ResultBean addCost(@RequestBody PayCostBean payCostBean) {
        payCostBean.setTime(System.currentTimeMillis());
        payCostBean.setPayState(1);
        payCostBean.setIsCheck(1);
        int count = payCostMapper.addCost(payCostBean);
        return ResultUtil.getResultBean(count, "添加失败");
    }

    @RequestMapping("/updateCost")
    @ResponseBody
    public ResultBean updateCost(@RequestBody PayCostBean payCostBean) {
        int count = payCostMapper.updateCost(payCostBean);
        return ResultUtil.getResultBean(count, "修改失败");
    }

    @RequestMapping("/deleteCost")
    @ResponseBody
    public ResultBean deleteCost(@RequestBody Map<String, Integer> params) {
        int count = payCostMapper.deleteCost(params.get("id"));
        return ResultUtil.getResultBean(count, "删除失败");
    }

    @RequestMapping("/getCost")
    @ResponseBody
    public ResultBean getCost() {
        List<PayCostBean> payCostBeans = payCostMapper.getCost();
        return ResultUtil.getSuccessBean(payCostBeans);
    }

    @RequestMapping("/getCostByUid")
    @ResponseBody
    public ResultBean getCostByUid(@RequestParam("uid") String uid) {
        List<PayCostBean> payCostBeans = payCostMapper.getCostByUid(uid);
        return ResultUtil.getSuccessBean(payCostBeans);
    }
}
